package com.turing.post.webservice.impl;

import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.jws.WebService;

import com.turing.post.account.util.AccountSystemAddTradDetail;
import com.turing.post.account.util.AccountSystemAddTradDetailDao;
import com.turing.post.cardmanagement.util.ActivateCard;
import com.turing.post.cardmanagement.util.ActivateCardBusiness;
import com.turing.post.cardmanagement.util.ActivateCardDao;
import com.turing.post.cardmanagement.util.CardClassic;
import com.turing.post.cardmanagement.util.CardClassicChangePolicy;
import com.turing.post.cardmanagement.util.CardClassicChangePolicyDao;
import com.turing.post.cardmanagement.util.CardClassicDao;
import com.turing.post.cardmanagement.util.CardStockDao;
import com.turing.post.cardtransactions.util.CardTransBusiness;
import com.turing.post.cardtransactions.util.ChangeCardClassicObject;
import com.turing.post.cardtransactions.util.ChangeCardClassicResult;
import com.turing.post.cardtransactions.util.ExtendExpiredObject;
import com.turing.post.cardtransactions.util.ExtendExpiredResult;
import com.turing.post.common.util.IdType;
import com.turing.post.common.util.IdTypeDao;
import com.turing.post.common.util.MerchantOper;
import com.turing.post.common.util.MerchantOperBusiness;
import com.turing.post.common.util.PCPSCommonDao;
import com.turing.post.common.util.SysOpUser;
import com.turing.post.common.util.SysOperLog;
import com.turing.post.common.util.SysOperLogDao;
import com.turing.post.datatranfer.util.CardControlBusiness;
import com.turing.post.datatranfer.util.CardTradDetailBusiness;
import com.turing.post.datatranfer.util.CardkindBusiness;
import com.turing.post.datatranfer.util.EntityCardBusiness;
import com.turing.post.datatranfer.util.OldIssueBranchBusiness;
import com.turing.post.datatranfer.util.OldSalebranchBusiness;
import com.turing.post.datatranfer.util.OldUserBusiness;
import com.turing.post.datatranferpibs.util.TradHistoryDetailDao;
import com.turing.post.datatranferpmbs.util.OldMerchantBusiness;
import com.turing.post.datatranferpmbs.util.PMBSMchTradDetailBusiness;
import com.turing.post.datatranferpmbs.util.SortInfoTranferBusiness;
import com.turing.post.organization.util.Merchant;
import com.turing.post.organization.util.MerchantDao;
import com.turing.post.selfwebservice.util.CardHolderUser;
import com.turing.post.selfwebservice.util.CardHolderUserBusiness;
import com.turing.post.selfwebservice.util.CardHolderUserLink;
import com.turing.post.selfwebservice.util.SelfWSLogonResult;
import com.turing.post.transaction.util.MchTradDetail;
import com.turing.post.transaction.util.MchTradDetailDao;
import com.turing.post.util.CommonWebResult;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSUtil;
import com.turing.post.util.PCPSWebInput;

/**
 * 前台网站服务
 * 
 * @author zxp
 * @Jan 19, 2013
 */
@WebService(name = "WebWscImplPortType", serviceName = "WebWscImpl")
public class WebWscImpl {
	// 公用PCPSException异常返回
	private CommonWebResult PCPSException(PCPSApplicationException p) {
		PCPSUtil.Log(p.getSubSysName(), p);
		return new CommonWebResult(PCPSUtil.FAILED, p.getErrCodeCategory(), p
				.getErrMsg());
	}

	// 公用Exception异常返回
	private CommonWebResult Exception(Exception e) {
		PCPSUtil.Log(e.getMessage(), e);
		return new CommonWebResult(PCPSUtil.FAILED,
				CommonWebResult.THROW_EXCEPTION,
				CommonWebResult.THROW_EXCEPTION_MSG);
	}

	@EJB(mappedName = "common.impl.SysOperLogDaoImpl")
	private SysOperLogDao sysOperLogDaoImpl;
	// 证件类型
	@EJB(mappedName = "common.impl.IdTypeDaoImpl")
	private IdTypeDao idTypeDaoImpl;

	// 日志文件记录
	@EJB(mappedName = "common.impl.PCPSCommonDaoImpl")
	private PCPSCommonDao commonDaoImpl;

	/**
	 * 根据主键查询证件类型
	 * 
	 * @return
	 */
	public IdType getIdTypeByIdTypeId(BigInteger idTypeId) {
		return idTypeDaoImpl.getIdTypeByIdTypeId(idTypeId);
	}

	/**
	 * 查询证件类型列表，不分页
	 * 
	 * @return
	 */
	public List<IdType> getIdTypeIdList() {
		return idTypeDaoImpl.getIdTypeIdList();
	}

	/**
	 * 根据分类查询证件类型列表，不分页
	 * 
	 * @return
	 */
	public List<IdType> getIdTypeIdListByCategory(String category) {
		return idTypeDaoImpl.getIdTypeIdListByCategory(category);
	}

	// 商户操作员模块开始
	@EJB(mappedName = "common.impl.MerchantOperBusinessImpl")
	private MerchantOperBusiness merchantOperBusinessImpl;

	/**
	 * 商户操作员登录
	 * 
	 * @param merchantOper
	 *            商户操作员
	 * @return 登录成功返回实体 登录失败返回null
	 */
	public SelfWSLogonResult merchantOperLogon(MerchantOper merchantOper) {
		MerchantOper oper = null;
		try {
			oper = merchantOperBusinessImpl.merchantOperLogon(merchantOper);
		} catch (PCPSApplicationException p) {
			PCPSUtil.Log(p.getSubSysName(), p);
			return new SelfWSLogonResult(PCPSUtil.FAILED, p
					.getErrCodeCategory(), p.getErrMsg());
		} catch (Exception e) {
			PCPSUtil.Log(e.getMessage(), e);
			new SelfWSLogonResult(PCPSUtil.FAILED,
					CommonWebResult.THROW_EXCEPTION,
					CommonWebResult.THROW_EXCEPTION_MSG);
		}
		return new SelfWSLogonResult(oper);
	}

	/**
	 * 添加商户操作员
	 * 
	 * @param merchantOper
	 *            商户操作员
	 */
	public CommonWebResult insertMerchantOper(MerchantOper merchantOper) {
		try {
			merchantOperBusinessImpl.insertMerchantOper(merchantOper);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 修改商户操作员
	 * 
	 * @param merchantOper
	 *            商户操作员
	 */
	public CommonWebResult updateMerchantOper(MerchantOper merchantOper) {
		try {
			merchantOperBusinessImpl.updateMerchantOper(merchantOper);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 根据商户操作员主键查询商户操作员信息
	 * 
	 * @param mrchOperId
	 *            商户操作员Id
	 * @return 商户操作员信息
	 */
	public MerchantOper getMerchantOperByMrchOperId(BigInteger mrchOperId) {
		return merchantOperBusinessImpl.getMerchantOperByMrchOperId(mrchOperId);
	}

	/**
	 * 分页查询所有商户操作员
	 * 
	 * @param page
	 *            页数
	 * @return 商户操作员列表
	 */
	public List<MerchantOper> getMerchantOpers(Integer page) {
		return merchantOperBusinessImpl.getMerchantOpers(page);
	}

	/**
	 * 查询所有商户操作员总数
	 * 
	 * @return 所有商户操作员总数
	 */
	public Integer getMerchantOpersCount() {
		return merchantOperBusinessImpl.getMerchantOpersCount();
	}

	/**
	 * 根据商户号分页查询商户所属操作员
	 * 
	 * @param merchantNo
	 *            商户号
	 * @param page
	 *            页数
	 * @return 商户所属操作员列表
	 */
	public List<MerchantOper> getMerchantOpersByMerchantNo(String merchantNo,
			Integer page) throws PCPSApplicationException {
		return merchantOperBusinessImpl.getMerchantOpersByMerchantNo(
				merchantNo, page);
	}

	/**
	 * 根据商户号查询商户所属操作员总数
	 * 
	 * @param merchantNo
	 *            商户号
	 * @return 商户所属操作员总数
	 */
	public Integer getMerchantOpersCountByMerchantNo(String merchantNo) {
		return merchantOperBusinessImpl
				.getMerchantOpersCountByMerchantNo(merchantNo);
	}

	/**
	 * 修改商户操作员密码
	 * 
	 * @param merchantOper
	 *            商户操作员
	 * @param newPassWord
	 *            新密码
	 */
	public CommonWebResult changeMerchantOperPwd(MerchantOper merchantOper,
			String newPassWord) {
		try {
			merchantOperBusinessImpl.changeMerchantOperPwd(merchantOper,
					newPassWord);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 根据商户操作员登录名查询商户操作员
	 * 
	 * @param merchantOperLogonName
	 *            商户操作员登录名
	 * @return 商户操作员实体信息
	 */
	public MerchantOper getMerchantOperQuestionByMrchOperLogonName(
			String merchantOperLogonName) {
		return merchantOperBusinessImpl
				.getMerchantOperQuestionByMrchOperLogonName(merchantOperLogonName);
	}

	/**
	 * 商户操作员找回密码
	 * 
	 * @param merchantOper
	 *            商户操作员
	 */
	public CommonWebResult getLossPasswordByMerchantOper(
			MerchantOper merchantOper) {
		try {
			merchantOperBusinessImpl.getLossPassword(merchantOper);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	// 商户操作员模块结束
	// 自助网站持卡用户模块开始
	@EJB(mappedName = "selfwebservice.impl.CardHolderUserBusinessImpl")
	CardHolderUserBusiness cardHolderUserBusinessImpl;

	/**
	 * 持卡用户登录
	 * 
	 * @param cardHolderUser
	 *            持卡用户
	 * @return 登录成功返回实体 登录失败返回null
	 */
	public SelfWSLogonResult CardHolderUserLogon(CardHolderUser cardHolderUser) {
		CardHolderUser user = null;
		try {
			user = cardHolderUserBusinessImpl
					.CardHolderUserLogon(cardHolderUser);
		} catch (PCPSApplicationException p) {
			PCPSUtil.Log(p.getSubSysName(), p);
			return new SelfWSLogonResult(PCPSUtil.FAILED, p
					.getErrCodeCategory(), p.getErrMsg());
		} catch (Exception e) {
			PCPSUtil.Log(e.getMessage(), e);
			new SelfWSLogonResult(PCPSUtil.FAILED,
					CommonWebResult.THROW_EXCEPTION,
					CommonWebResult.THROW_EXCEPTION_MSG);
		}
		return new SelfWSLogonResult(user);
	}

	/**
	 * 添加注册用户
	 * 
	 * @param cardHolderUser
	 *            持卡用户
	 * @param cardNo
	 *            卡号
	 * @param cardPwd
	 *            卡密码，明文
	 */
	public CommonWebResult insertCardHolderUser(CardHolderUser cardHolderUser,
			String cardNo, String cardPwd) {
		try {
			cardHolderUserBusinessImpl.insertCardHolderUser(cardHolderUser,
					cardNo, cardPwd);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 修改注册用户
	 * 
	 * @param cardHolderUser
	 *            持卡用户
	 */
	public CommonWebResult updateCardHolderUser(CardHolderUser cardHolderUser) {
		try {
			cardHolderUserBusinessImpl.updateCardHolderUser(cardHolderUser);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 根据注册用户主键查询注册用户信息
	 * 
	 * @param cardHolderUserId
	 *            持卡用户Id
	 * @return 持卡用户信息
	 */
	public CardHolderUser getCardHolderUserByCardHolderUserId(
			BigInteger cardHolderUserId) {
		return cardHolderUserBusinessImpl
				.getCardHolderUserByCardHolderUserId(cardHolderUserId);
	}

	/**
	 * 分页查询所有注册用户
	 * 
	 * @param page
	 *            页数
	 * @return 持卡用户列表
	 */
	public List<CardHolderUser> getCardHolderUsers(Integer page) {
		return cardHolderUserBusinessImpl.getCardHolderUsers(page);
	}

	/**
	 * 查询所有注册用户总数
	 * 
	 * @return 所有注册用户总数
	 */
	public Integer getCardHolderUsersCount() {
		return cardHolderUserBusinessImpl.getCardHolderUsersCount();
	}

	/**
	 * 条件分页查询所有注册用户
	 * 
	 * @param email
	 *            邮箱
	 * @param name
	 *            姓名
	 * @param idTypeId
	 *            证件类型
	 * @param idNo
	 *            证件号
	 * @param sex
	 *            性别
	 * @param status
	 *            状态
	 * @param page
	 *            页数
	 * @return 持卡用户列表
	 */

	public List<CardHolderUser> getCardHolderUsersByCondition(String email,
			String name, Integer idTypeId, String idNo, String sex,
			String status, Integer page) {
		return cardHolderUserBusinessImpl.getCardHolderUsersByCondition(email,
				name, idTypeId, idNo, sex, status, page);
	}

	/**
	 * 条件分页查询所有注册用户总数
	 * 
	 * @param email
	 *            邮箱
	 * @param name
	 *            姓名
	 * @param idTypeId
	 *            证件类型
	 * @param idNo
	 *            证件号
	 * @param sex
	 *            性别
	 * @param status
	 *            状态
	 * @return 持卡用户总数
	 */
	public Integer getCardHolderUsersCountByCondition(String email,
			String name, Integer idTypeId, String idNo, String sex,
			String status) {
		return cardHolderUserBusinessImpl.getCardHolderUsersCountByCondition(
				email, name, idTypeId, idNo, sex, status);
	}

	/**
	 * 修改注册用户密码
	 * 
	 * @param cardHolderUser
	 *            持卡用户
	 * @param newPassWord
	 *            新密码
	 */
	public CommonWebResult changeCardHolderUserPwd(
			CardHolderUser cardHolderUser, String newPassWord) {
		try {
			cardHolderUserBusinessImpl.changeCardHolderUserPwd(cardHolderUser,
					newPassWord);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 根据持卡用户登录名获取持卡用户密码问题
	 * 
	 * @param logonName
	 *            持卡用户登录名
	 * @return
	 */
	public CardHolderUser getCardHolderUserQuestionByLogonName(String logonName) {
		return cardHolderUserBusinessImpl
				.getCardHolderUserQuestionByLogonName(logonName);
	}

	/**
	 * 自助网站注册用户找回密码
	 * 
	 * @param cardHolderUser
	 *            持卡用户
	 */
	public CommonWebResult getLossPasswordByCardHolderUser(
			CardHolderUser cardHolderUser) {
		try {
			cardHolderUserBusinessImpl.getLossPassword(cardHolderUser);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 根据注册用户ID获取注册用户关联卡列表
	 * 
	 * @param cardHolderUserId
	 * @return
	 */
	public List<CardHolderUserLink> getCardHolderUserLinksByCardHolderUserId(
			BigInteger cardHolderUserId) {
		return cardHolderUserBusinessImpl
				.getCardHolderUserLinksByCardHolderUserId(cardHolderUserId);
	}

	/**
	 * 持卡用户添加关联卡
	 * 
	 * @param cardHolderUserLink
	 *            关联卡
	 * @param cardPwd
	 *            卡密码
	 */
	public CommonWebResult insertCardHolderUserLink(
			CardHolderUserLink cardHolderUserLink, String cardPwd) {
		try {
			cardHolderUserBusinessImpl.insertCardHolderUserLink(
					cardHolderUserLink, cardPwd);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 取消持卡用户卡关联
	 * 
	 * @param cardHolderUserLink
	 * @return
	 */
	public CommonWebResult cancelCardHolderUserLink(
			CardHolderUserLink cardHolderUserLink) {
		try {
			cardHolderUserBusinessImpl
					.cancelCardHolderUserLink(cardHolderUserLink);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 根据卡号查询发卡商下网站登录代理用户信息
	 * 
	 * @param cardNo
	 *            卡号
	 * @return
	 */
	public SysOpUser getInternetAgentSysOpUserByCardNo(String cardNo) {
		return cardHolderUserBusinessImpl
				.getInternetAgentSysOpUserByCardNo(cardNo);
	}

	// 自助网站注册用户模块结束
	// 商户模块
	@EJB(mappedName = "organization.impl.MerchantDaoImpl")
	private MerchantDao merchantDaoImpl;

	/**
	 * 根据商户编号查询
	 * 
	 * @param merchantNo
	 * @return
	 */
	public Merchant getMerchantByMerchantNo(String merchantNo) {
		return merchantDaoImpl.getMerchantByMerchantNo(merchantNo);
	}

	// 商户交易流水
	@EJB(mappedName = "transaction.impl.MchTradDetailDaoImpl")
	private MchTradDetailDao mchTradDetailDaoImpl;

	/**
	 * 商户交易流程查询
	 * 
	 * @param merchantNo
	 *            商户号
	 * @param mrchBrchNo
	 *            商户机构号
	 * @param terminalNo
	 *            终端号
	 * @param startTime
	 *            起始时间
	 * @param endTime
	 *            终止时间
	 * @param startAmount
	 *            起始金额
	 * @param endAmount
	 *            终止金额
	 * @param tranCode
	 *            交易码
	 * @param page
	 *            页码
	 * @return
	 */
	public List<MchTradDetail> getMchTradDetailListByCondition(
			String issueCompanyNo, String merchantNo, String mrchBrchNo,
			String terminalNo, String startTime, String endTime,
			BigInteger startAmount, BigInteger endAmount, String tranCode,
			String cardNo, Integer page) {
		return mchTradDetailDaoImpl.getMchTradDetailListByCondition(
				issueCompanyNo, merchantNo, mrchBrchNo, terminalNo, startTime,
				endTime, startAmount, endAmount, tranCode, cardNo, page);
	}

	public Integer getMchTradDetailTotalByCondition(String issueCompanyNo,
			String merchantNo, String mrchBrchNo, String terminalNo,
			String startTime, String endTime, BigInteger startAmount,
			BigInteger endAmount, String tranCode, String cardNo) {
		return mchTradDetailDaoImpl.getMchTradDetailTotalByCondition(
				issueCompanyNo, merchantNo, mrchBrchNo, terminalNo, startTime,
				endTime, startAmount, endAmount, tranCode, cardNo);
	}

	/**
	 * 根据主键查询商户交易明细
	 * 
	 * @param mtd
	 * @return
	 */
	public MchTradDetail getMchTradDetailByPrimaryKey(MchTradDetail mtd) {
		return mchTradDetailDaoImpl.getMchTradDetailByPrimaryKey(mtd);
	}

	@EJB(mappedName = "cardmanagement.impl.ActivateCardDaoImpl")
	private ActivateCardDao activateCardDaoImpl;

	// @EJB(mappedName = "cardmanagement.impl.ActivateCardBusinessImpl")
	// private ActivateCardBusiness activateCardBusinessImpl;

	/**
	 * 激活卡卡信息查询,根据卡号条件
	 * 
	 * @param cardNo
	 * @return
	 */
	public ActivateCard getActivateCardByCardNo(String cardNo) {
		return activateCardDaoImpl.getActivateCardByCardNo(cardNo);
	}

	@EJB(mappedName = "cardmanagement.impl.CardClassicDaoImpl")
	private CardClassicDao cardClassicDaoImpl;

	/**
	 * 根据卡种类Id返回对应实体
	 * 
	 * @param id
	 * @return
	 */
	public CardClassic getCardClassicByCardClassicId(BigInteger CardClassicId) {
		return cardClassicDaoImpl.getCardClassicByCardClassicId(CardClassicId);
	}

	@EJB(mappedName = "cardtransactions.impl.CardTransBusinessImpl")
	private CardTransBusiness cardTransBusinessImpl;

	/**
	 * 卡延期
	 * 
	 * @param extendExpiredObject
	 *            对象
	 * @return
	 */
	public ExtendExpiredResult CardExtendExpired(PCPSWebInput webInput,
			ExtendExpiredObject extendExpiredObject) {
		ExtendExpiredObject res = null;
		try {
			res = cardTransBusinessImpl.ExtendExpired(webInput,
					extendExpiredObject);
		} catch (PCPSApplicationException p) {
			PCPSUtil.Log(p.getSubSysName(), p);
			return new ExtendExpiredResult(PCPSUtil.FAILED, p
					.getErrCodeCategory(), p.getErrMsg());
		} catch (Exception e) {
			PCPSUtil.Log(e.getMessage(), e);
			return new ExtendExpiredResult(PCPSUtil.FAILED,
					CommonWebResult.THROW_EXCEPTION,
					CommonWebResult.THROW_EXCEPTION_MSG);
		}
		return new ExtendExpiredResult(res);
	}

	@EJB(mappedName = "cardmanagement.impl.CardClassicChangePolicyDaoImpl")
	private CardClassicChangePolicyDao cardClassicChangePolicyDaoImpl;

	public List<CardClassicChangePolicy> getCardClassicChangePolicyListByFromClassicId(
			BigInteger fromClassicId) {
		return cardClassicChangePolicyDaoImpl
				.getCardClassicChangePolicyListByFromClassicId(fromClassicId);
	}

	/**
	 * 根据主键查询卡种类变更费率
	 * 
	 * @param cccp
	 * @return
	 */
	public CardClassicChangePolicy getCardClassicChangePolicyByPK(
			CardClassicChangePolicy cccp) {
		return cardClassicChangePolicyDaoImpl
				.getCardClassicChangePolicyByPK(cccp);
	}

	/**
	 * 变更卡种类
	 * 
	 * @param changeCardClassicObject
	 *            对象
	 * @return
	 */
	public ChangeCardClassicResult changeCardClassic(PCPSWebInput webInput,
			ChangeCardClassicObject changeCardClassicObject) {
		ChangeCardClassicObject res = null;
		try {
			res = cardTransBusinessImpl.ChangeCardClassic(webInput,
					changeCardClassicObject);
		} catch (PCPSApplicationException p) {
			PCPSUtil.Log(p.getSubSysName(), p);
			return new ChangeCardClassicResult(PCPSUtil.FAILED, p
					.getErrCodeCategory(), p.getErrMsg());
		} catch (Exception e) {
			PCPSUtil.Log(e.getMessage(), e);
			return new ChangeCardClassicResult(PCPSUtil.FAILED,
					CommonWebResult.THROW_EXCEPTION,
					CommonWebResult.THROW_EXCEPTION_MSG);
		}
		return new ChangeCardClassicResult(res);
	}

	/**
	 * 根据卡号修改密码
	 * 
	 * @param cardNo
	 * @param oldPwd
	 * @param newPwd
	 * @param operId
	 * @param remark
	 * @return
	 */
	public CommonWebResult changeCardPassword(PCPSWebInput webInput,
			String cardNo, String oldPwd, String newPwd, BigInteger operId,
			String remark) {
		try {
			cardTransBusinessImpl.ChangePassword(cardNo, oldPwd, newPwd,
					operId, remark);
			// 日志记录
			sysOperLogDaoImpl.insertSysOperLogInfo(webInput,
					SysOperLog.operType_Add, "根据卡号修改密码", "CardNo: " + cardNo);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 根据卡号或卡序号获取子账户列表
	 * 
	 * @param cardNo
	 * @return
	 */
	// public List<SubAccount> getSubAccListByCardNoOrCardSeqNo(
	// PCPSWebInput webInput, String cardNo) {
	// return activateCardDaoImpl.getSubAccListByCardNoOrCardSeqNo(webInput,
	// cardNo);
	// }
	// @EJB(mappedName = "account.impl.SubAccountDetailDaoImpl")
	// private SubAccountDetailDao subAccountDetailDaoImpl;
	/**
	 * 组合条件查询子账户交易明细
	 * 
	 * @param webInput
	 * @param cardNo
	 * @param startTime
	 * @param endTime
	 * @param page
	 * @return
	 */
	// public List<SubAccountDetail> getSubAccDetailListByCondition(
	// PCPSWebInput webInput, String cardNo, BigInteger subAccNo,
	// String startTime, String endTime, Integer page)
	// throws PCPSApplicationException {
	// return subAccountDetailDaoImpl.getSubAccDetailListByCondition(webInput,
	// cardNo, subAccNo, startTime, endTime, page);
	// }
	/**
	 * 组合条件查询子账户交易明细总数
	 * 
	 * @param webInput
	 * @param cardNo
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	// public BigInteger getSubAccDetailListTotal(PCPSWebInput webInput,
	// String cardNo, BigInteger subAccNo, String startTime, String endTime)
	// throws PCPSApplicationException {
	// return subAccountDetailDaoImpl.getSubAccDetailListTotal(webInput,
	// cardNo, subAccNo, startTime, endTime);
	// }
	@EJB(mappedName = "account.impl.AccountSystemAddTradDetailDaoImpl")
	private AccountSystemAddTradDetailDao accSysTradDetailDaoImpl;

	/**
	 * 根据输入条件,查询账户交易附加流水(pcps和自助网站:卡交易明细查询)
	 * 
	 * @param webInput
	 * @param cardNo
	 * @param startTime
	 * @param endTime
	 * @param page
	 * @return
	 */
	public List<AccountSystemAddTradDetail> getAccountSystemAddTradDetailByCondition(
			PCPSWebInput webInput, String cardNo, String startTime,
			String endTime, Integer page) throws PCPSApplicationException {
		return accSysTradDetailDaoImpl
				.getAccountSystemAddTradDetailByCondition(webInput, cardNo,
						startTime, endTime, page);
	}

	/**
	 * 根据输入条件,查询账户交易附加流水(pcps和自助网站:卡交易明细查询) 总数
	 * 
	 * @param webInput
	 * @param cardNo
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	public BigInteger getAccountSystemAddTradDetailTotalByCondition(
			PCPSWebInput webInput, String cardNo, String startTime,
			String endTime) throws PCPSApplicationException {
		return accSysTradDetailDaoImpl
				.getAccountSystemAddTradDetailTotalByCondition(webInput,
						cardNo, startTime, endTime);
	}

	@EJB(mappedName = "cardmanagement.impl.ActivateCardBusinessImpl")
	private ActivateCardBusiness activateCardBusinessImpl;

	/**
	 * 卡临时挂失
	 * 
	 * @param webInput
	 * @param cardNo
	 * @param remark
	 * @return
	 */
	public CommonWebResult cardTemporaryLoss(PCPSWebInput webInput,
			String cardNo, String remark) throws PCPSApplicationException {
		try {
			activateCardBusinessImpl
					.cardTemporaryLoss(webInput, cardNo, remark);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 数据迁移=========================================
	 */

	// 已清分数据迁移
	@EJB(mappedName = "datatranferpmbs.impl.SortInfoTranferBusinessImpl")
	private SortInfoTranferBusiness SortInfoTranferBusinessImpl;

	// 卡交易明细
	@EJB(mappedName = "datatranfer.impl.CardTradDetailBusinessImpl")
	private CardTradDetailBusiness cardTradDetailBusinessImpl;

	// /**
	// * 数据迁移
	// *
	// * @param key
	// * @param page
	// * @throws PCPSApplicationException
	// * @throws PCPSApplicationException
	// */
	// public Integer tranferCardTradDetail(Integer page, Integer num)
	// throws PCPSApplicationException {
	// return cardTradDetailBusinessImpl.tranferCardTradDetail(page, num);
	// }

	// 卡控制表
	@EJB(mappedName = "datatranfer.impl.CardControlBusinessImpl")
	private CardControlBusiness cardControlBusinessImpl;

	public CommonWebResult insertMakeCardControl(String issuecompanyno,
			String cardManufactureId, String cardFaceId) {
		try {
			cardControlBusinessImpl.insertMakeCardControl(issuecompanyno,
					cardManufactureId, cardFaceId);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	@EJB(mappedName = "datatranferpmbs.impl.PMBSMchTradDetailBusinessImpl")
	private PMBSMchTradDetailBusiness pMBSMchTradDetailBusinessImpl;

	/**
	 * 老数据库数据通过报文调用接口进入新系统
	 * 
	 * @param trandate
	 * @throws PCPSApplicationException
	 */
	public CommonWebResult tranferPMBSDataByTranDate(String icNo, String ip,
			Integer port, String trandate, String merchantNo, boolean tag) {
		try {
			pMBSMchTradDetailBusinessImpl.tranferPMBSDataByTranDate(icNo, ip,
					port, trandate, merchantNo, tag);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	@EJB(mappedName = "datatranferpibs.impl.TradHistoryDetailDaoImpl")
	private TradHistoryDetailDao tradHistoryDetailDaoImpl;

	public List<Object[]> getCardManagerBranchNoList(String trandate) {
		return tradHistoryDetailDaoImpl.getCardManagerBranchNoList(trandate);
	}

	/**
	 * 日终后 便民驿站 表数据
	 */
	public CommonWebResult tranferPIBSDataByTranDate(String branchNo,
			String ip, Integer port, String tranDate, String merchantNo,
			String faceMrchBrchNo, String webMrchBrchNo) {
		try {
			cardTradDetailBusinessImpl.tranferPIBSDataByTranDate(branchNo, ip,
					port, tranDate, merchantNo, faceMrchBrchNo, webMrchBrchNo);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 交易流水表日期
	 * 
	 * @return
	 */
	public List<Object[]> getMchTradDetailTranDateList() {
		return pMBSMchTradDetailBusinessImpl.getMchTradDetailTranDateList();
	}

	public void transferPMBSMchTradDetail(String merchantNo, String tranDate)
			throws PCPSApplicationException {
		pMBSMchTradDetailBusinessImpl.transferPMBSMchTradDetail(merchantNo,
				tranDate);
	}

	public void transferPMBSMchAddTradSummary(String date)
			throws PCPSApplicationException {
		pMBSMchTradDetailBusinessImpl.transferPMBSMchAddTradSummary(date);
	}

	public void deleteMapPMBSTradDetail() {
		pMBSMchTradDetailBusinessImpl.deleteMapPMBSTradDetail();
	}

	/**
	 * 基础数据---商户
	 */
	@EJB(mappedName = "datatranferpmbs.impl.OldMerchantBusinessImpl")
	private OldMerchantBusiness oldMerchantBusinessImpl;

	public CommonWebResult insertNewMerchant(PCPSWebInput webInput,
			String issuecompanyno, String regionNo, String incomeBranchId,
			String developBranchNo) throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			oldMerchantBusinessImpl.insertNewMerchant(webInput, issuecompanyno,
					regionNo, incomeBranchId, developBranchNo);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 基础数据---卡种类
	 */
	@EJB(mappedName = "datatranfer.impl.CardkindBusinessImpl")
	private CardkindBusiness cardkindBusinessImpl;

	public CommonWebResult insertCardClassic(String issuecompanyno)
			throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			cardkindBusinessImpl.insertCardClassic(issuecompanyno);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 基础数据---发卡机构
	 */
	@EJB(mappedName = "datatranfer.impl.OldIssueBranchBusinessImpl")
	private OldIssueBranchBusiness oldIssueBranchBusinessImpl;

	public CommonWebResult insertNewIssueBranch(PCPSWebInput webInput,
			String issuecompanyno, String regionNo)
			throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			oldIssueBranchBusinessImpl.insertNewIssueBranch(webInput,
					issuecompanyno, regionNo);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 基础数据---销售机构
	 */
	@EJB(mappedName = "datatranfer.impl.OldSaleBranchBusinessImpl")
	private OldSalebranchBusiness oldSaleBranchBusinessImpl;

	public CommonWebResult insertNewSaleBranch(PCPSWebInput webInput,
			String issuecompanyno, String regionNo, String issbranchno,
			String incomeBranchId) throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			oldSaleBranchBusinessImpl.insertNewSaleBranch(webInput,
					issuecompanyno, regionNo, issbranchno, incomeBranchId);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 基础数据-用户迁移
	 */
	@EJB(mappedName = "datatranfer.impl.OldUserBusinessImpl")
	private OldUserBusiness oldUserBusinessImpl;

	public CommonWebResult insertNewUser(PCPSWebInput webInput,
			String branchno, String issuecompanyno, String roleid)
			throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			oldUserBusinessImpl.insertNewUser(webInput, branchno,
					issuecompanyno, roleid);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 数据迁移-卡库存迁移
	 */
	@EJB(mappedName = "datatranfer.impl.EntityCardBusinessImpl")
	private EntityCardBusiness entityCardBusiness;
	@EJB(mappedName = "cardmanagement.impl.CardStockDaoImpl")
	private CardStockDao cardStockDao;

	/**
	 * 卡库存迁移
	 * 
	 * @param number
	 * @return
	 * @throws PCPSApplicationException
	 */
	public CommonWebResult getEntityCardListInsertCardStock(String number,
			String issueCompanyNo) throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			entityCardBusiness.getEntityCardListInsertCardStock(number,
					issueCompanyNo);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 已清分数据迁移
	 * 
	 * @param number
	 * @return
	 * @throws PCPSApplicationException
	 */
	public CommonWebResult sortInfoTranfer(String issuecompanyno,boolean b)
			throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			int daycount = SortInfoTranferBusinessImpl.getdaycount()+1;
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			
			Date date1 = formatter.parse("2009-12-23");
			if(b)
				SortInfoTranferBusinessImpl.transferPMBSSortInfo(date1,
					issuecompanyno);
			int i = 0;
			while (i < daycount) {
				Date date = SortInfoTranferBusinessImpl.getSortTranferDate();
				SortInfoTranferBusinessImpl.transferPMBSSortInfo(date,
						issuecompanyno);
				i++;
			}
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 出入库明细添加
	 * 
	 * @param issueBranchNo
	 * @param batchNo
	 * @return
	 * @throws PCPSApplicationException
	 */
	public CommonWebResult insertIssueCardStockDetail(String issueBranchNo,
			String batchNo, BigInteger cardFaceId, BigInteger operId)
			throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			entityCardBusiness.insertIssueCardStockDetail(issueBranchNo,
					batchNo, cardFaceId, operId);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 分组查询入库卡归属机构和批次号
	 * 
	 * @return
	 */
	public List<Object[]> getCardStockList() {
		return cardStockDao.getCardStockList();
	}

	/**
	 * 数据迁移-激活卡迁移
	 */
	@EJB(mappedName = "datatranfer.impl.ActivateCardBusinessImpl")
	private com.turing.post.datatranfer.util.ActivateCardBusiness acbImpl;
	@EJB(mappedName = "datatranfer.impl.ActivateCardDaoImpl")
	private com.turing.post.datatranfer.util.ActivateCardDao acdImpl;

	/**
	 * 激活卡迁移
	 * 
	 * @throws PCPSApplicationException
	 */
	public CommonWebResult tranferActivateCard(String issueCompanyNo,
			String batchNo) throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			acbImpl.tranferActivateCard(issueCompanyNo, batchNo);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}

	/**
	 * 从老系统中找到所有卡批次号
	 * 
	 * @return
	 */
	public List<Object[]> getBatchNoFromOldActivateCard() {
		return acdImpl.getBatchNoFromOldActivateCard();
	}

	// 自动售卡
	public CommonWebResult saleOldCard(String icNo, String startDate,
			String endDate, BigInteger userid, BigInteger faceid)
			throws PCPSApplicationException {
		commonDaoImpl.setDataTranferLogPath("DataTranfer");
		try {
			cardTradDetailBusinessImpl.saleOldCard(icNo, startDate, endDate,
					userid, faceid);
		} catch (PCPSApplicationException p) {
			return PCPSException(p);
		} catch (Exception e) {
			return Exception(e);
		}
		return new CommonWebResult();
	}
}
